<?php
class News extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->helper ( 'url' );
		$this->load->library ( 'form_validation' );
	}
	
	function newsList() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$this->load->model ( 'Mnews' );
			$this->load->library ( 'pagination' );
			
			$data ['num'] = $this->Mnews->getNewsNum ();
			$data ['page'] = $this->uri->segment ( 4, 0 );
			
			$config ['base_url'] = base_url () . '/admin/news/newsList/';
			$config ['total_rows'] = $data ['num'];
			$config ['per_page'] = PAGE_SHOW_NUM;
			$config ['uri_segment'] = 4;
			$config ['num_links'] = 2;
			$this->pagination->initialize ( $config );
			
			$data ['newslist'] = $this->Mnews->getNewsList ( $data ['page'], PAGE_SHOW_NUM );
			$data ['class'] = 'News';
			$data ['className'] = '纽斯达新闻';
			
			$data ['authority'] = $this->session->userdata ( 'authority' );
			$data ['adminName'] = $this->session->userdata ( 'adminName' );
			
			$this->load->view ( 'admin/header', $data );
			$this->load->view ( 'admin/nav' );
			$this->load->view ( 'admin/news_list' );
			$this->load->view ( 'admin/footer' );
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有管理最新动态的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function activityList() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$this->load->model ( 'Mnews' );
			$this->load->library ( 'pagination' );
			
			$data ['num'] = $this->Mnews->getActivityNum ();
			$data ['page'] = $this->uri->segment ( 4, 0 );
			
			$config ['base_url'] = base_url () . '/admin/news/activityList/';
			$config ['total_rows'] = $data ['num'];
			$config ['per_page'] = PAGE_SHOW_NUM;
			$config ['uri_segment'] = 4;
			$config ['num_links'] = 2;
			$this->pagination->initialize ( $config );
			
			$data ['newslist'] = $this->Mnews->getActivityList ( $data ['page'], PAGE_SHOW_NUM );
			$data ['class'] = 'Activity';
			$data ['className'] = '商户活动';
			
			$data ['authority'] = $this->session->userdata ( 'authority' );
			$data ['adminName'] = $this->session->userdata ( 'adminName' );
			
			$this->load->view ( 'admin/header', $data );
			$this->load->view ( 'admin/nav' );
			$this->load->view ( 'admin/news_list' );
			$this->load->view ( 'admin/footer' );
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有管理最新动态的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function cardPostList() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$this->load->model ( 'Mnews' );
			$this->load->library ( 'pagination' );
			
			$data ['num'] = $this->Mnews->getCardPostNum ();
			$data ['page'] = $this->uri->segment ( 4, 0 );
			
			$config ['base_url'] = base_url () . '/admin/news/cardPostList/';
			$config ['total_rows'] = $data ['num'];
			$config ['per_page'] = PAGE_SHOW_NUM;
			$config ['uri_segment'] = 4;
			$config ['num_links'] = 2;
			$this->pagination->initialize ( $config );
			
			$data ['newslist'] = $this->Mnews->getCardPostList ( $data ['page'], PAGE_SHOW_NUM );
			$data ['class'] = 'CardPost';
			$data ['className'] = '卡片公告';
			
			$data ['authority'] = $this->session->userdata ( 'authority' );
			$data ['adminName'] = $this->session->userdata ( 'adminName' );
			
			$this->load->view ( 'admin/header', $data );
			$this->load->view ( 'admin/nav' );
			$this->load->view ( 'admin/news_list' );
			$this->load->view ( 'admin/footer' );
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有管理最新动态的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function addNews() {
		$this->load->helper ( 'form' );
		$this->load->model ( 'Mnews' );
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			
			$this->form_validation->set_rules ( 'title', '标题', 'trim|required|max_length[100]' );
			$this->form_validation->set_rules ( 'show', '首页推送', '' );
			$data ['details'] = $this->input->post ( 'editor' );
			
			if ($this->form_validation->run () == TRUE) {
				$data ['title'] = $this->input->post ( 'title' );
				$data ['class'] = 'N';
				$data ['details'] = $this->input->post ( 'editor' );
				if ($this->input->post ( 'show' ) === 'T')
					$data ['show'] = 'T';
				else
					$data ['show'] = 'F';
				$data ['updatePerson'] = $this->session->userdata ( 'adminName' );
				$data ['id'] = $this->Mnews->addNews ( $data );
				if ($data ['id']) {
					if ($_FILES ["userfile"] ["name"]) {
						$config ['upload_path'] = './uploads/news/';
						$config ['file_name'] = 'news_' . $data ['id'];
						$config ['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
						$config ['overwrite'] = true;
						$this->load->library ( 'upload', $config );
						
						if (! $this->upload->do_upload ( 'userfile' ))
							$data ['msg'] = $this->upload->display_errors ();
						else {
							$tmp = $this->upload->data ();
							$datan ['newsImage'] = base_url () . "uploads/news/" . $tmp ['file_name'];
							$datan ['id'] = $data ['id'];
							$config ['image_library'] = 'gd2';
							$config ['source_image'] = "./uploads/news/" . $tmp ['file_name'];
							$config ['maintain_ratio'] = FALSE;
							$config ['width'] = 700;
							$config ['height'] = 200;
							$this->load->library ( 'image_lib', $config );
							
							if ($this->image_lib->resize ()) {
								if ($this->Mnews->updateNews ( $datan )) {
									$data ['msg'] = '纽斯达新闻添加成功！';
								} else {
									$data ['msg'] = '纽斯达新闻添加出错！';
								}
							} else {
								$data ['msg'] = $this->image_lib->display_errors ();
							}
						}
					} else
						$data ['msg'] = '纽斯达新闻添加成功！';
				} else {
					$data ['msg'] = '数据插入失败！';
				}
				$data ['url'] = base_url () . 'admin/news/newsList';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['className'] = '纽斯达新闻';
				$data ['class'] = 'News';
				$data ['form'] = array ('id' => 'newsAddForm', 'enctype' => "multipart/form-data" );
				
				$data ['authority'] = $this->session->userdata ( 'authority' );
				$data ['adminName'] = $this->session->userdata ( 'adminName' );
				
				$this->load->view ( 'admin/header', $data );
				$this->load->view ( 'admin/nav' );
				$this->load->view ( 'admin/news_add' );
				$this->load->view ( 'admin/footer' );
			}
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有添加纽斯达的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function addActivity() {
		$this->load->helper ( 'form' );
		$this->load->model ( 'Mnews' );
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			
			$this->form_validation->set_rules ( 'title', '标题', 'trim|required|max_length[100]' );
			$this->form_validation->set_rules ( 'show', '首页推送', '' );
			$data ['details'] = $this->input->post ( 'editor' );
			
			if ($this->form_validation->run () == TRUE) {
				$data ['title'] = $this->input->post ( 'title' );
				$data ['class'] = 'A';
				$data ['details'] = $this->input->post ( 'editor' );
				if ($this->input->post ( 'show' ) === 'T')
					$data ['show'] = 'T';
				else
					$data ['show'] = 'F';
				$data ['updatePerson'] = $this->session->userdata ( 'adminName' );
				$data ['id'] = $this->Mnews->addNews ( $data );
				if ($data ['id']) {
					if ($_FILES ["userfile"] ["name"]) {
						$config ['upload_path'] = './uploads/news/';
						$config ['file_name'] = 'activity_' . $data ['id'];
						$config ['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
						$config ['overwrite'] = true;
						$this->load->library ( 'upload', $config );
						
						if (! $this->upload->do_upload ( 'userfile' ))
							$data ['msg'] = $this->upload->display_errors ();
						else {
							$tmp = $this->upload->data ();
							$datan ['newsImage'] = base_url () . "uploads/news/" . $tmp ['file_name'];
							$datan ['id'] = $data ['id'];
							$config ['image_library'] = 'gd2';
							$config ['source_image'] = "./uploads/news/" . $tmp ['file_name'];
							$config ['maintain_ratio'] = FALSE;
							$config ['width'] = 700;
							$config ['height'] = 200;
							$this->load->library ( 'image_lib', $config );
							
							if ($this->image_lib->resize ()) {
								if ($this->Mnews->updateNews ( $datan )) {
									$data ['msg'] = '商户活动添加成功！';
								} else {
									$data ['msg'] = '商户活动添加出错！';
								}
							} else {
								$data ['msg'] = $this->image_lib->display_errors ();
							}
						}
					} else
						$data ['msg'] = '商户活动添加成功！';
				} else {
					$data ['msg'] = '数据插入失败！';
				}
				$data ['url'] = base_url () . 'admin/news/activityList';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['className'] = '商户活动';
				$data ['class'] = 'Activity';
				$data ['form'] = array ('id' => 'activityAddForm', 'enctype' => "multipart/form-data" );
				
				$data ['authority'] = $this->session->userdata ( 'authority' );
				$data ['adminName'] = $this->session->userdata ( 'adminName' );
				
				$this->load->view ( 'admin/header', $data );
				$this->load->view ( 'admin/nav' );
				$this->load->view ( 'admin/news_add' );
				$this->load->view ( 'admin/footer' );
			}
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有添加商户活动的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function addCardPost() {
		$this->load->helper ( 'form' );
		$this->load->model ( 'Mnews' );
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			
			$this->form_validation->set_rules ( 'title', '标题', 'trim|required|max_length[100]' );
			$this->form_validation->set_rules ( 'show', '首页推送', '' );
			$data ['details'] = $this->input->post ( 'editor' );
			
			if ($this->form_validation->run () == TRUE) {
				$data ['title'] = $this->input->post ( 'title' );
				$data ['class'] = 'C';
				$data ['details'] = $this->input->post ( 'editor' );
				if ($this->input->post ( 'show' ) === 'T')
					$data ['show'] = 'T';
				else
					$data ['show'] = 'F';
				$data ['updatePerson'] = $this->session->userdata ( 'adminName' );
				$data ['id'] = $this->Mnews->addNews ( $data );
				if ($data ['id']) {
					if ($_FILES ["userfile"] ["name"]) {
						$config ['upload_path'] = './uploads/news/';
						$config ['file_name'] = 'cardPost_' . $data ['id'];
						$config ['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
						$config ['overwrite'] = true;
						$this->load->library ( 'upload', $config );
						
						if (! $this->upload->do_upload ( 'userfile' ))
							$data ['msg'] = $this->upload->display_errors ();
						else {
							$tmp = $this->upload->data ();
							$datan ['newsImage'] = base_url () . "uploads/news/" . $tmp ['file_name'];
							$datan ['id'] = $data ['id'];
							$config ['image_library'] = 'gd2';
							$config ['source_image'] = "./uploads/news/" . $tmp ['file_name'];
							$config ['maintain_ratio'] = FALSE;
							$config ['width'] = 700;
							$config ['height'] = 200;
							$this->load->library ( 'image_lib', $config );
							
							if ($this->image_lib->resize ()) {
								if ($this->Mnews->updateNews ( $datan )) {
									$data ['msg'] = '卡片公告添加成功！';
								} else {
									$data ['msg'] = '卡片公告添加出错！';
								}
							} else {
								$data ['msg'] = $this->image_lib->display_errors ();
							}
						}
					} else
						$data ['msg'] = '卡片公告添加成功！';
				} else {
					$data ['msg'] = '数据插入失败！';
				}
				$data ['url'] = base_url () . 'admin/news/cardPostList';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['className'] = '卡片公告';
				$data ['class'] = 'CardPost';
				$data ['form'] = array ('id' => 'cardPostAddForm', 'enctype' => "multipart/form-data" );
				
				$data ['authority'] = $this->session->userdata ( 'authority' );
				$data ['adminName'] = $this->session->userdata ( 'adminName' );
				
				$this->load->view ( 'admin/header', $data );
				$this->load->view ( 'admin/nav' );
				$this->load->view ( 'admin/news_add' );
				$this->load->view ( 'admin/footer' );
			}
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有添加卡片公告的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function editNews() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$data ['id'] = $this->uri->segment ( 4, 0 );
			$this->load->model ( 'Mnews' );
			
			$this->form_validation->set_rules ( 'title', '标题', 'trim|required|max_length[100]' );
			
			if ($this->form_validation->run () == TRUE) {
				$data ['title'] = $this->input->post ( 'title' );
				$data ['details'] = $this->input->post ( 'editor' );
				if ($this->input->post ( 'show' ) === 'T')
					$data ['show'] = 'T';
				else
					$data ['show'] = 'F';
				$data ['updatePerson'] = $this->session->userdata ( 'adminName' );
				
				if ($_FILES ["userfile"] ["name"]) {
					$config ['upload_path'] = './uploads/news/';
					$config ['file_name'] = 'news_' . $data ['id'];
					$config ['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
					$config ['overwrite'] = true;
					$this->load->library ( 'upload', $config );
					
					if (! $this->upload->do_upload ( 'userfile' ))
						$data ['msg'] = $this->upload->display_errors ();
					else {
						$tmp = $this->upload->data ();
						$data ['newsImage'] = base_url () . "uploads/news/" . $tmp ['file_name'];
						$config ['image_library'] = 'gd2';
						$config ['source_image'] = "./uploads/news/" . $tmp ['file_name'];
						$config ['maintain_ratio'] = FALSE;
						$config ['width'] = 700;
						$config ['height'] = 200;
						$this->load->library ( 'image_lib', $config );
						
						if ($this->image_lib->resize ()) {
							if ($this->Mnews->updateNews ( $data )) {
								$data ['msg'] = '纽斯达新闻更新成功！';
							} else {
								$data ['msg'] = '纽斯达新闻更新出错！';
							}
						} else {
							$data ['msg'] = $this->image_lib->display_errors ();
						}
					}
				} else {
					if ($this->Mnews->updateNews ( $data )) {
						$data ['msg'] = '纽斯达新闻更新成功！';
					} else {
						$data ['msg'] = '纽斯达新闻更新出错！';
					}
				}
				$data ['url'] = base_url () . 'admin/news/newsList';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['news'] = $this->Mnews->getItembyIdClass ( $data ['id'], 'N' );
				if ($this->input->post ()) {
					$data ['news'] ['title'] = $this->input->post ( 'title' );
					$data ['news'] ['show'] = $this->input->post ( 'show' );
					$data ['news'] ['details'] = $this->input->post ( 'editor' );
				}
				$data ['className'] = '纽斯达新闻';
				$data ['class'] = 'News';
				$data ['form'] = array ('id' => 'newsEditForm', 'enctype' => "multipart/form-data" );
				
				$data ['authority'] = $this->session->userdata ( 'authority' );
				$data ['adminName'] = $this->session->userdata ( 'adminName' );
				
				$this->load->view ( 'admin/header', $data );
				$this->load->view ( 'admin/nav' );
				$this->load->view ( 'admin/news_edit' );
				$this->load->view ( 'admin/footer' );
			}
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有编辑纽斯达新闻的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function editActivity() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$data ['id'] = $this->uri->segment ( 4, 0 );
			$this->load->model ( 'Mnews' );
			
			$this->form_validation->set_rules ( 'title', '标题', 'trim|required|max_length[100]' );
			
			if ($this->form_validation->run () == TRUE) {
				$data ['title'] = $this->input->post ( 'title' );
				$data ['details'] = $this->input->post ( 'editor' );
				if ($this->input->post ( 'show' ) === 'T')
					$data ['show'] = 'T';
				else
					$data ['show'] = 'F';
				$data ['updatePerson'] = $this->session->userdata ( 'adminName' );
				
				if ($_FILES ["userfile"] ["name"]) {
					$config ['upload_path'] = './uploads/news/';
					$config ['file_name'] = 'activity_' . $data ['id'];
					$config ['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
					$config ['overwrite'] = true;
					$this->load->library ( 'upload', $config );
					
					if (! $this->upload->do_upload ( 'userfile' ))
						$data ['msg'] = $this->upload->display_errors ();
					else {
						$tmp = $this->upload->data ();
						$data ['newsImage'] = base_url () . "uploads/news/" . $tmp ['file_name'];
						$config ['image_library'] = 'gd2';
						$config ['source_image'] = "./uploads/news/" . $tmp ['file_name'];
						$config ['maintain_ratio'] = FALSE;
						$config ['width'] = 700;
						$config ['height'] = 200;
						$this->load->library ( 'image_lib', $config );
						
						if ($this->image_lib->resize ()) {
							if ($this->Mnews->updateNews ( $data )) {
								$data ['msg'] = '商户活动更新成功！';
							} else {
								$data ['msg'] = '商户活动更新出错！';
							}
						} else {
							$data ['msg'] = $this->image_lib->display_errors ();
						}
					}
				} else {
					if ($this->Mnews->updateNews ( $data )) {
						$data ['msg'] = '商户活动更新成功！';
					} else {
						$data ['msg'] = '商户活动更新出错！';
					}
				}
				$data ['url'] = base_url () . 'admin/news/activityList';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['news'] = $this->Mnews->getItembyIdClass ( $data ['id'], 'A' );
				if ($this->input->post ()) {
					$data ['news'] ['title'] = $this->input->post ( 'title' );
					$data ['news'] ['show'] = $this->input->post ( 'show' );
					$data ['news'] ['details'] = $this->input->post ( 'editor' );
				}
				$data ['className'] = '商户活动';
				$data ['class'] = 'Activity';
				$data ['form'] = array ('id' => 'activityEditForm', 'enctype' => "multipart/form-data" );
				
				$data ['authority'] = $this->session->userdata ( 'authority' );
				$data ['adminName'] = $this->session->userdata ( 'adminName' );
				
				$this->load->view ( 'admin/header', $data );
				$this->load->view ( 'admin/nav' );
				$this->load->view ( 'admin/news_edit' );
				$this->load->view ( 'admin/footer' );
			}
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有编辑商户活动的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function editCardPost() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$data ['id'] = $this->uri->segment ( 4, 0 );
			$this->load->model ( 'Mnews' );
			
			$this->form_validation->set_rules ( 'title', '标题', 'trim|required|max_length[100]' );
			
			if ($this->form_validation->run () == TRUE) {
				$data ['title'] = $this->input->post ( 'title' );
				$data ['details'] = $this->input->post ( 'editor' );
				if ($this->input->post ( 'show' ) === 'T')
					$data ['show'] = 'T';
				else
					$data ['show'] = 'F';
				$data ['updatePerson'] = $this->session->userdata ( 'adminName' );
				
				if ($_FILES ["userfile"] ["name"]) {
					$config ['upload_path'] = './uploads/news/';
					$config ['file_name'] = 'cardPost_' . $data ['id'];
					$config ['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
					$config ['overwrite'] = true;
					$this->load->library ( 'upload', $config );
					
					if (! $this->upload->do_upload ( 'userfile' ))
						$data ['msg'] = $this->upload->display_errors ();
					else {
						$tmp = $this->upload->data ();
						$data ['newsImage'] = base_url () . "uploads/news/" . $tmp ['file_name'];
						$config ['image_library'] = 'gd2';
						$config ['source_image'] = "./uploads/news/" . $tmp ['file_name'];
						$config ['maintain_ratio'] = FALSE;
						$config ['width'] = 700;
						$config ['height'] = 200;
						$this->load->library ( 'image_lib', $config );
						
						if ($this->image_lib->resize ()) {
							if ($this->Mnews->updateNews ( $data )) {
								$data ['msg'] = '卡片公告更新成功！';
							} else {
								$data ['msg'] = '卡片公告更新出错！';
							}
						} else {
							$data ['msg'] = $this->image_lib->display_errors ();
						}
					}
				} else {
					if ($this->Mnews->updateNews ( $data )) {
						$data ['msg'] = '卡片公告更新成功！';
					} else {
						$data ['msg'] = '卡片公告更新出错！';
					}
				}
				$data ['url'] = base_url () . 'admin/news/cardPostList';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['news'] = $this->Mnews->getItembyIdClass ( $data ['id'], 'C' );
				if ($this->input->post ()) {
					$data ['news'] ['title'] = $this->input->post ( 'title' );
					$data ['news'] ['show'] = $this->input->post ( 'show' );
					$data ['news'] ['details'] = $this->input->post ( 'editor' );
				}
				$data ['className'] = '卡片公告';
				$data ['class'] = 'CardPost';
				$data ['form'] = array ('id' => 'cardPostEditForm', 'enctype' => "multipart/form-data" );
				
				$data ['authority'] = $this->session->userdata ( 'authority' );
				$data ['adminName'] = $this->session->userdata ( 'adminName' );
				
				$this->load->view ( 'admin/header', $data );
				$this->load->view ( 'admin/nav' );
				$this->load->view ( 'admin/news_edit' );
				$this->load->view ( 'admin/footer' );
			}
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有编辑卡片公告的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function deleNews() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$data ['id'] = $this->uri->segment ( 4, 0 );
			$this->load->model ( 'Mnews' );
			
			if ($this->Mnews->delItembyIdClass ( $data ['id'], 'N' )) {
				$data ['msg'] = '纽斯达新闻删除成功！';
			} else
				$data ['msg'] = '纽斯达新闻删除失败！';
			
			$data ['url'] = base_url () . 'admin/news/newsList';
			$this->load->view ( 'admin/admin_message', $data );
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有删除纽斯达新闻的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function deleActivity() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$data ['id'] = $this->uri->segment ( 4, 0 );
			$this->load->model ( 'Mnews' );
			
			if ($this->Mnews->delItembyIdClass ( $data ['id'], 'A' )) {
				$data ['msg'] = '商户活动删除成功！';
			} else
				$data ['msg'] = '商户活动删除失败！';
			
			$data ['url'] = base_url () . 'admin/news/activityList';
			$this->load->view ( 'admin/admin_message', $data );
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有删除商户活动的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
	
	function deleCardPost() {
		if (($this->session->userdata ( 'authority' ) === '0') || ($this->session->userdata ( 'authority' ) === '1')) {
			$data ['id'] = $this->uri->segment ( 4, 0 );
			$this->load->model ( 'Mnews' );
			
			if ($this->Mnews->delItembyIdClass ( $data ['id'], 'C' )) {
				$data ['msg'] = '卡片公告删除成功！';
			} else
				$data ['msg'] = '卡片公告删除失败！';
			
			$data ['url'] = base_url () . 'admin/news/cardPostList';
			$this->load->view ( 'admin/admin_message', $data );
		} else {
			if ($this->session->userdata ( 'adminName' )) {
				$data ['msg'] = '您没有删除卡片公告的权限！';
				$data ['url'] = base_url () . 'admin/home';
				$this->load->view ( 'admin/admin_message', $data );
			} else {
				$data ['msg'] = '请先登录！';
				$data ['url'] = base_url () . 'admin/home/login';
				$this->load->view ( 'admin/admin_message', $data );
			}
		}
	}
}